@page "/admin/roles"
@using NetCorePal.D3Shop.Web.Admin.Client.Extensions
@using NetCorePal.D3Shop.Web.Admin.Client.Components.Identity.Role

@attribute [ClientPermission(PermissionCodes.RoleManagement)]

<Table
    TItem="RoleResponse"
    @ref="_table"
    DataSource="_pagedRoles.Items"
    Total="_pagedRoles.Total"
    @bind-PageIndex="_roleQueryRequest.PageIndex"
    @bind-PageSize="_roleQueryRequest.PageSize"
    OnChange="Table_OnChange"
    Loading="_loading">
    <PaginationTemplate>
        <Pagination Class="@context.PaginationClass"
                    Total="context.Total"
                    PageSize="context.PageSize"
                    Current="context.PageIndex"
                    ShowSizeChanger
                    OnChange="context.HandlePageChange"/>
    </PaginationTemplate>
    <TitleTemplate>
        <GridRow Gutter="8" Justify="space-between">
            <GridCol Span="4">
                <Title Level="3">角色列表</Title>
            </GridCol>
            <GridCol Span="8" Offset="10">
                <Search Placeholder="搜索名称" @bind-Value="_roleQueryRequest.Name" OnSearch="() => OnSearch()"/>
            </GridCol>
            <GridCol Span="2">
                <AuthorizeView>
                    @if (context.CheckPermission(PermissionCodes.RoleCreate))
                    {
                        <AddRole OnItemAdded="HandleItemAdded"></AddRole>
                    }
                </AuthorizeView>
            </GridCol>
        </GridRow>
    </TitleTemplate>
    <ColumnDefinitions Context="row">
        <PropertyColumn Title="名称" Property="c => c.Name"/>
        <PropertyColumn Title="描述" Property="c => c.Description"/>
        <ActionColumn Title="操作">
            <AuthorizeView>
                @if (context.CheckPermission(PermissionCodes.RoleEdit))
                {
                    <CascadingValue Value="@row">
                        <EditRoleInfo OnRowUpdated="HandleItemUpdated"></EditRoleInfo>
                    </CascadingValue>
                }
                @if (context.CheckPermission(PermissionCodes.RoleUpdatePermissions))
                {
                    <CascadingValue Value="@row">
                        <EditRolePermissions></EditRolePermissions>
                    </CascadingValue>
                }
                @if (context.CheckPermission(PermissionCodes.RoleDelete))
                {
                    <a @onclick="() => Delete(row)">删除</a>
                }
            </AuthorizeView>
        </ActionColumn>
    </ColumnDefinitions>
</Table>